home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97a.txt / 000064_icon-group-sender _Mon Mar 3 15:03:06 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 4 Mar 1997 08:23:18 MST
  2. To: icon-group@cs.arizona.edu
  3. Date: Mon, 03 Mar 1997 15:03:06 -0700
  4. From: Steve Wampler <swampler@gemini.edu>
  5. Message-Id: <331B4A9A.4C37@gemini.edu>
  6. Organization: Gemini 8m Telescopes Project
  7. Sender: icon-group-request@cs.arizona.edu
  8. References: <5ff37v$r3n$1@gaia.ns.utk.edu>
  9. Subject: Re: reading reals
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11. Status: RO
  12. Content-Length: 1015
  13.  
  14. Mark Kot wrote:
  15. >         What is the Icon analog to the C
  16. > programming instruction
  17. >         scanf("%f%f", &x, &y);   ?
  18. > That is, what is the simplest (or most standard)
  19. > way to read two real numbers (with intervening
  20. > and/or preceding white space) from a line of
  21. > input in Icon ?
  22.  
  23. Hmmm, 'simplest' is interesting.  I assume you really
  24. mean %f, and not %g, and that you're happy with pretty
  25. simple error checking.  Here's one approach:
  26.  
  27. procedure main()
  28.  
  29.     every line := !&input do {
  30.         line ? {
  31.         x := get_real() | write(&errout, "Bad real: ",&subject)
  32.         y := get_real() | write(&errout, "Bad real: ",&subject)
  33.             }
  34.     write("x = ", x)
  35.     write("y = ", y)
  36.         }
  37.  
  38. end
  39.  
  40. procedure get_real()
  41.     static digitseq
  42.     initial digitseq := '+-.' ++ &digits
  43.  
  44.     suspend real( (tab(upto(digitseq)), tab(many(digitseq))) )
  45. end
  46.  
  47. -- 
  48. Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under
  49. AURA)]
  50. The Gods that smiled upon your birth are laughing now. -- fortune cookie
  51.